package pri.tool.pump;


public class PumpInterface {
    private final static String TAG ="jPump";
    IDataCallback dataCallback;  // 数据回调

    static {
        System.loadLibrary("pump");
    }

    //开关蜂鸣器
    public int OnOffBuzzer(int isOn) {
        return native_OnOffBuzzer(isOn);
    }
    //开关led
    public int OnOffLed(int isOn) {
        return native_OnOffLed(isOn);
    }
    //开关空气泵,常开,产生负压
    public int OnOffPump(int isOn) {
        return native_OnOffPump(isOn);
    }
    //开关空气阀,在线程中不停的开关开关, 即可得到设置的负压,会有关系表可查
    //即控制主界面的负压等级
    public int OnOffAir(int isOn) {
        return native_OnOffAir(isOn);
    }
    //开关步进马达,即开始推针
    public int OnOffMotor(int isOn) {
        return native_OnOffMotor(isOn);
    }
    //设置马达方向,即主界面推针方向
    public int SetMotorDirect(int dir) {
        return native_setMotorDirect(dir);
    }
    //设置马达频率和步数
    //freq:频率值，控制速度 即主界面上的推进速度
    //step:脉冲次数, 1个脉冲大概0.0001毫米 按照这个算法：6096个脉冲移动0.6096mm
    public int setMotorStep(int freq, int step) {
        return native_setMotorStep(freq, step);
    }

//-------------------------------------------------

    //-1表示获取失败,以下都是
    public int getBuzzer() {
        return native_getBuzzer();
    }
    public int getLed() {
        return native_getLed();
    }
    public int getPump() {
        return native_getPump();
    }
    public int getAir() {
        return native_getAir();
    }
    public int getMotor() {
        return native_getMotor();
    }
    public int getMotorDirect() {
        return native_getMotorDirect();
    }
    public int get_mPa() {
        return native_get_mPa();
    }

    //获取上次设置频率，当前还剩多少步step, int[0]--freq, int[1]--step
    public int[] getMotorStep() {
        long ret = native_getMotorStep();
        int[] freq_step = new int[2];
        freq_step[0] = (int)(ret & 0xffffffff); //freq
        freq_step[1] = (int)((ret >> 32) & 0xffffffff);//剩余step
        return freq_step;
    }

    private native final int native_OnOffBuzzer(int isOn);
    private native final int native_OnOffLed(int isOn);
    private native final int native_OnOffPump(int isOn);
    private native final int native_OnOffAir(int isOn);
    private native final int native_OnOffMotor(int isOn);
    private native final int native_setMotorDirect(int isOn);
    private native final int native_setMotorStep(int freq, int step);

    private native final int native_getBuzzer();
    private native final int native_getLed();
    private native final int native_getPump();
    private native final int native_getAir();
    private native final int native_getMotor();
    private native final int native_getMotorDirect();
    private native final int native_get_mPa();
    private native final long native_getMotorStep();

}
